<template>
	<div v-if="loading">
		<aiprocess> </aiprocess>
	</div>
</template>

<script setup lang="ts">
import aiprocess from "./index.vue";
import { fakelogin, getInfo } from "@/api/user/index";
import { getToken, setToken } from "@/utils/auth";
import { useUserStore } from "@/store";
const userStore = useUserStore();
let router = useRouter();
const loading = ref(false);
const faketestlogin = async () => {
	if (getToken() && !loading.value) {
		loading.value = true;
		return;
	}
	let data = {
		username: "testw",
		password: "123456",
	};
	console.log(data);
	let res = await fakelogin(data);
	if (res.code !== 200) {
		console.log(res);
		return;
	}
	setToken(res.token);
	let userRes = await getInfo();
	let userInfo = userRes.user;
	console.log(userInfo);
	userStore.setInfo({
		userName: userInfo.userName,
		nickName: userInfo.nickName,
		userCode: userInfo.userCode,
		userId: userInfo.userId,
		userRole: userRes.permissions[0],
		ftpInfo: userRes.ftp.protocolType + "://" + userRes.ftp.serverIp + ":" + userRes.ftp.serverPort,
		ftpPwd: userInfo.ftpPwd,
	});
	loading.value = true;
	console.log("fakelogin");
};
onMounted(() => {
	console.log(loading.value, "fakelogin");

	faketestlogin();
	console.log(loading.value, "fakelogin");
});
</script>

<style></style>
